using Microsoft.AspNetCore.Mvc;
using ZR.Model.FacManage.Dto;
using ZR.Model.FacManage;
using ZR.Service.FacManage.IFacManageService;
using ZR.Admin.WebApi.Filters;
using ZR.Model;

//创建时间：2025-04-20
namespace ZR.Admin.WebApi.Controllers.FacManage
{
    /// <summary>
    /// 库位信息
    /// </summary>
    [Verify]
    [Route("FacManage/FacLoc")]
    public class FacLocController : BaseController
    {
        /// <summary>
        /// 库位信息接口
        /// </summary>
        private readonly IFacLocService _FacLocService;

        public FacLocController(IFacLocService FacLocService)
        {
            _FacLocService = FacLocService;
        }

        /// <summary>
        /// 查询库位信息列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("pageList")]
        [ActionPermissionFilter(Permission = "fac:loc:list")]
        public IActionResult PageFacLoc([FromQuery] FacLocQueryDto parm)
        {
            var response = _FacLocService.GetPageList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 获取货位树信息
        /// </summary>
        /// <param name="disabledWhse"></param>
        /// <returns></returns>
        [HttpGet("treeList")]
        [ActionPermissionFilter(Permission = "fac:loc:list")]
        public IActionResult GetTreeList(bool disabledWhse)
        {
            var response = _FacLocService.GetTreeList(disabledWhse);
            return SUCCESS(response);
        }

        /// <summary>
        /// 查询库位信息详情
        /// </summary>
        /// <param name="LocId"></param>
        /// <returns></returns>
        [HttpGet("{LocId}")]
        [ActionPermissionFilter(Permission = "fac:loc:query")]
        public IActionResult GetFacLoc(string LocId)
        {
            var response = _FacLocService.GetInfo(LocId);
            
            var info = response.Adapt<FacLocDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加库位信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "fac:loc:add")]
        [Log(Title = "库位信息", BusinessType = BusinessType.INSERT)]
        public IActionResult AddFacLoc([FromBody] FacLocDto parm)
        {
            var modal = parm.Adapt<FacLoc>().ToCreate(HttpContext);

            var response = _FacLocService.AddFacLoc(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新库位信息
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "fac:loc:edit")]
        [Log(Title = "库位信息", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateFacLoc([FromBody] FacLocDto parm)
        {
            var modal = parm.Adapt<FacLoc>().ToUpdate(HttpContext);
            var response = _FacLocService.UpdateFacLoc(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除库位信息
        /// </summary>
        /// <returns></returns>
        [HttpPost("delete")]
        [ActionPermissionFilter(Permission = "fac:loc:delete")]
        [Log(Title = "库位信息", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteFacLoc([FromBody] string[] ids)
        {
            return ToResponse(_FacLocService.Delete(ids));
        }

    }
}